package 排序算法;

public class 选择排序 {

    public static void main(String[] args) {
        Integer[] arrays = {1, 56, 32, 56, 12, 77, 88, 21};


        for (int end = arrays.length - 1; end > 0; end--) {
            int maxIndex = 0;//记录最大值的下标
            for (int begin = 1; begin <= end; begin++) {
                if (arrays[maxIndex] < arrays[begin]) {
                    maxIndex = begin;
                }
            }
            //与最后位置交换
            int tmp = arrays[end];
            arrays[end] = arrays[maxIndex];
            arrays[maxIndex] = tmp;
        }

        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i] + "_");
        }
    }

}
